package ysq.xyg.web.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.web.model.po.WebCorporation;
import ysq.xyg.web.model.po.WebCorporationUser;
import ysq.xyg.web.model.vo.WebCorporationUserVo;
import ysq.xyg.web.model.vo.WebCorporationVo;
import ysq.xyg.web.service.WebCorporationService;
import ysq.xyg.web.service.WebCorporationUserService;
import ysq.xyg.web.util.WebBaseContent;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 业务模块-社团信息controller层
 *
 * @author shengQiang yu
 * @date 2019-5-13 9:19:17
 */
@RestController
public class WebCorporationController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(WebCorporationController.class);
    @Resource
    private WebCorporationUserService webCorporationUserService;
    @Resource
    private WebCorporationService webCorporationService;

    private WebCorporation webCorporation;

    /**
     * 分页查询
     *
     * @param webCorporationVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-5-13 9:19:17
     */
    @BaseLog(module = "业务模块",className = "社团信息",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webCorporation/page",method = RequestMethod.POST)
    public ReturnEntity page(WebCorporationVo webCorporationVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = webCorporationService.page(webCorporationVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-5-13 9:19:17
     */
    @RequestMapping(value = "/webCorporation/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/web/webCorporationUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            webCorporation = webCorporationService.selectByPrimaryKey(id);
            view.addObject("webCorporation", webCorporation);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-5-13 9:19:17
     */
    @BaseLog(module = "业务模块",className = "社团信息",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webCorporation/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return webCorporationService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param webCorporationVo Vo对象
     * @author shengQiang yu
     * @date 2019-5-13 9:19:17
     */
    @BaseLog(module = "业务模块",className = "社团信息",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webCorporation/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,WebCorporationVo webCorporationVo){
        return webCorporationService.addOrUpdate(webCorporationVo,acceptCurrentUser(request));
    }
    /**
     * 打印页面
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-5-13 9:19:17
     */
    @RequestMapping(value = "/webCorporation/getPrint",method = RequestMethod.GET)
    public ModelAndView getPrint(String id){
        ModelAndView view = new ModelAndView("/web/webCorporationPrint");
        webCorporation = webCorporationService.selectByPrimaryKey(id);
        List<WebCorporationUser> fqrUserList=webCorporationUserService.acceptList(new WebCorporationUserVo(webCorporation.getId(), WebBaseContent.WEB_CORPORATION_USER_TYPE_FQR));
        List<WebCorporationUser> fzrUserList=webCorporationUserService.acceptList(new WebCorporationUserVo(webCorporation.getId(), WebBaseContent.WEB_CORPORATION_USER_TYPE_FZR));
        view.addObject("fqrUserList", fqrUserList);
        view.addObject("fzrUserList", fzrUserList);
        view.addObject("webCorporation", webCorporation);
        return view;
    }
}